package org.lonetree.tc.webapp.forms;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

public class CourseForm extends ActionForm {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String id;				//1
	private String course_code;		//CPSC
	private String course_number;	//410
	private String course_title;	//Advanced Software Engineering
	
	@Override
	public ActionErrors validate(ActionMapping mapping,	HttpServletRequest request) {
		
		 ActionErrors errors = new ActionErrors();
	     
		 if (course_code == null)
			 errors.add("course_code", new ActionMessage("admincourses.addcourse.error.code"));
		 if (course_code.length() != 4)
			 errors.add("course_code_length", new ActionMessage("admincourses.addcourse.error.code.length"));	     
		 if (course_number == null)
	    	 errors.add("course_num", new ActionMessage("admincourses.addcourse.error.number"));
	     if (course_number.length() != 3)
	    	 errors.add("course_number_length", new ActionMessage("admincourses.addcourse.error.number.length"));	     
	     if ((course_title == null) || (course_title.length() < 1))
	    	 errors.add("course_title", new ActionMessage("admincourses.addcourse.error.title"));
	     
	     return errors;
	}
	
	public String getId() {
		return id;
	}
	
	public void setId(String id) {
		this.id = id;
	}
	
	public String getCourse_code() {
		return course_code;
	}
	
	public void setCourse_code(String course_code) {
		this.course_code = course_code;
	}
	
	public String getCourse_number() {
		return course_number;
	}
	
	public void setCourse_number(String course_number) {
		this.course_number = course_number;
	}
	
	public String getCourse_title() {
		return course_title;
	}

	public void setCourse_title(String course_title) {
		this.course_title = course_title;
	}
}
